package org.spring.jruby.erbtest.core;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.servlet.view.AbstractUrlBasedView;

/**
 *
 * @author oleg
 */
public class ErbView extends AbstractUrlBasedView {

    @Override
    protected void renderMergedOutputModel(
            final Map<String, Object> model,
            final HttpServletRequest request,
            final HttpServletResponse response) throws Exception {
        final ErbLoader erbResolver = (ErbLoader) getApplicationContext().getBean(ErbLoader.class);
        final ModelAndView mav = (ModelAndView) model.get("modelAndView");
        final String out = erbResolver.resolveView(getServletContext().getRealPath(getUrl()),
                mav.getModel());
        response.getWriter().write(out);
    }
    
}
